﻿using Microsoft.Xna.Framework;

namespace Babylon.Primitives
{
    /// <summary>
    /// Textured cube
    /// </summary>
    public class TexturedCube : CubeBase<VertexPositionNormalTexture>
    {
        /// <summary>
        /// Creates an instance of a textured cube
        /// </summary>
        /// <param name="width">width of the cube</param>
        /// <param name="height">height of the cube</param>
        /// <param name="depth">depth of the cube</param>
        public TexturedCube(float width, float height, float depth)
            :base(width, height, depth)
        { }
        protected override void BeforeCreatingVertexArray()
        {
        }

        protected override VertexPositionNormalTexture CreateVertex(Vector3 position, Vector3 normal)
        {
            return new VertexPositionNormalTexture { Position = position, Normal = normal };
        }

        protected override void AfterCreatingVertexArray(VertexPositionNormalTexture[] vertices)
        {
            var texCoords = new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1) };
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i].TexCoords = texCoords[i % texCoords.Length];
            }
        }

        protected override Microsoft.Xna.Framework.Graphics.VertexDeclaration GetVertexDeclaration()
        {
            return VertexPositionNormalTexture.GetVertexDeclaration();
        }
    }
}
